/*
 * Copyright (c) 2006, 2022, webrx.cn All rights reserved.
 *
 */
package cn.ex;

import java.io.FileInputStream;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * <p>Project: javase2203 - Ex3
 * <p>Powered by webrx On 2022-08-15 09:33:53
 *
 * @author webrx [webrx@126.com]
 * @version 1.0
 * @since 17
 */
public class Ex3 {
    public static void main(String[] args) {
        try (var is = new FileInputStream("user.txt")) {
            String text = new String(is.readAllBytes());
            //System.out.println(text.lines().count());

            //统计单行注释
            //System.out.println(text.lines().filter(e->e.matches("\s*//.*")).count());

            //System.out.println(text.lines().filter(e->e.matches("\s*")).count());

            //System.out.println(text.lines().filter(e->e.matches("\s*/\\*[\r\n\s]\\*/\s*")).count());

            //System.out.println(text.lines().filter(e -> e.matches("\s*/\\*[\n\r\s.\\*]*?\\*/")).count());
            Pattern p = Pattern.compile("\s*/\\*[\r\n\s.\\*]*?\\*/");
            Matcher matcher = p.matcher(text);
            int rows = 0;
            while (matcher.find()) {
                rows+=matcher.group().lines().count();
            }
            System.out.println(rows);


        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
